package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product/baseTrademark")
public class BaseTrademarkController {
    @Autowired
    BaseTrademarkService baseTrademarkService;


    @GetMapping("{page}/{limit}")
    public Result getTrademarkPage(@PathVariable long page,
                                   @PathVariable long limit){

        Page<BaseTrademark> baseTrademarkPage = new Page<>(page, limit);
        //调用方法
      IPage iPage =  baseTrademarkService.getTradeMarkPage(baseTrademarkPage);
      return Result.ok(iPage);
    }

    //保存
    @PostMapping("save")
    public  Result saveBaseTrademark(@RequestBody BaseTrademark baseTrademark){
        //调用方法
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }
    //  删除方法
    @DeleteMapping("remove/{id}")
    public Result removeById(@PathVariable long id){
        //调用方法
        baseTrademarkService.removeById(id);

        return Result.ok();
    }
    //  根据Id 获取数据！
    @GetMapping("get/{id}")
    public Result getById(@PathVariable long id){
        //调用方法
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);

        return Result.ok();
    }

    //  修改：
    @PutMapping("/update")
    public Result update(@RequestBody BaseTrademark baseTrademark){
        //调用方法
        baseTrademarkService.updateById(baseTrademark);

        return Result.ok();
    }
    //查询全部品牌
    @GetMapping("getTrademarkList")
    public Result<List<BaseTrademark>> getTrademarkList() {
        List<BaseTrademark> trademarkList = baseTrademarkService.list(null);
        return Result.ok(trademarkList);
    }
}
